package com.chunguang.netty.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.chunguang.netty.comon.Client;
import com.chunguang.netty.domain.RequestData;
import com.chunguang.netty.domain.TransferData;
import com.chunguang.netty.listener.ApplicationFactory;
import com.chunguang.netty.service.RequestDataService;

import io.netty.channel.ChannelFuture;

 



@RestController
public class IndexController {

	@Autowired
	private RequestDataService service;
	
    @RequestMapping("/index")

    @ResponseBody
    public  String index() throws Exception {
    	Client c = Client.getInstance();
		ChannelFuture cf = c.getChannelFuture();
		
		ApplicationContext context1 = ApplicationFactory.getContext();
		System.out.println("dddddddd");
		RequestDataService service = (RequestDataService) context1.getBean("requestDataService");
		TransferData transferData = new TransferData();
		transferData.setCheckNumber("aaaaaaaaaaaaaaaaaa");
		transferData.setSync(0);
		service.insert(transferData );
		RequestData requestData2 = new RequestData();
		BeanUtils.copyProperties(transferData, requestData2, new String[]{"sync"});
		cf.channel().writeAndFlush(requestData2);
        return "hhhhhhh";
    }

    
	
	
	
	
	
	
	
}
